﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataService;

public partial class Account_yourinformation : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (UserLogin.IsAdmin)
            {
                YourInfomationSubmit1.Visible = false;
                MainContactSubmit1.Contact = UserLogin.Customer.MainContact;
            }
            else
            {
                MainContactSubmit1.Visible = false;
                YourInfomationSubmit1.User = UserLogin;
            }
        }
    }
    protected void btAddUser_Click(object sender, EventArgs e)
    {
        if (!YourInfomationSubmit1.Visible)
        {
            using (ContactService service = new ContactService())
            {
                service.SaveMainContact(UserLogin.Customer);
                Response.Redirect("Default.aspx");
            }
        }
        else
        {
            using (ContactService service = new ContactService())
            {
                DTO.User userUpdate = YourInfomationSubmit1.User;
                UserLogin.FirstName = userUpdate.FirstName;
                UserLogin.LastName = userUpdate.LastName;
                UserLogin.Email = userUpdate.Email;
                UserLogin.Phone = userUpdate.Phone;
                service.InsertUpdateUserInfo(UserLogin);
                Response.Redirect("Default.aspx");
            }
        }
    }
}